#{extends 'common/myHeader.html' /}
#{set title:'修改${model.comment}' /}
 <form class="layui-form layui-row layui-col-space10">
	<div class="layui-col-md9 layui-col-xs12">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md9 layui-col-xs7">
#foreach($field in $fieldList)
#if($field.isPk != "Y"&&${field.inputType}!="none")
#if(${field.inputType}=="textarea")
			    <div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}#if(!$field.nullable)<font color="red">*</font>#end</label>
			      <div class="layui-input-block"><textarea class="layui-textarea" id="${field.field}" placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end>${${model.modelL}?.${field.field}}</textarea></div>
			    </div>
#elseif(${field.inputType}=="date")
			    <div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}#if($field.validate=="date"||!$field.nullable)<font color="red">*</font>#end</label>
			      <div class="layui-input-block"><input class="layui-input " id="${field.field}" placeholder="请选择日期" readonly value="${${model.modelL}?.${field.field}.format('yyyy-MM-dd')}" #if($field.validate=="date")lay-verify="date"#elseif(!$field.nullable)lay-verify="required"#end/></div>
			    </div>
#elseif(${field.inputType}=="datetime")
			    <div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}#if($field.validate=="date"||!$field.nullable)<font color="red">*</font>#end</label>
			      <div class="layui-input-block"><input class="layui-input " id="${field.field}" placeholder="请选择日期和时间" readonly value="${${model.modelL}?.${field.field}.format('yyyy-MM-dd HH:mm:ss')}" #if($field.validate=="date")lay-verify="date"#elseif(!$field.nullable)lay-verify="required"#end/></div>
			    </div>
#elseif(${field.inputType}=="radio")
			    <div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}</label>
					<div class="layui-input-block">
#foreach($item in $field.inputValueMap.entrySet())
						<input  name="${field.field}" id="${field.field}"  type="radio" value="$!{item.key}" lay-skin="primary" #{ if ${model.modelL}?.${field.field}==$!{item.key}} checked="checked"#{/if} title="$!{item.value}">
#end
					</div>
			    </div>
#elseif(${field.inputType}=="file")
				<div class="layui-form-item">
			       <label class="layui-form-label">${field.comment}</label>
			       <div class="layui-input-block">
				       <div class="layui-col-md3 layui-col-xs5">
							<div class="layui-upload-list thumbBox mag0 magt3">
							<img alt="" src="${${model.modelL}?.${field.field}}" name="image" id="${field.field}src" class="layui-upload-img thumbImg",height= "150px",width= "200px"/>
							</div>
				      </div>
		               <input type="file" class="upload_file" name="imgFile" id="${field.field}file" onchange="uploadImageUser('${field.field}file','${field.field}src');" />
		              <span style="color:#999;" id="imageResolution"></span>
		              <input type="hidden" name="${field.field}" id="${field.field}" />
			       </div>
			     </div>
#elseif(${field.inputType}=="htmleditor")
				<div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}</label>
			      <div class="layui-input-block">
			      		<div class="xf_ht_news_conr">
			              <textarea class="xf_ht_jr_obttd_textarea" id="${field.field}">${${model.modelL}?.${field.field}}</textarea>
			            </div>
			      </div>
			    </div>
#elseif(${field.inputType}=="checkbox")
			    <div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}</label>
					<div class="">
#foreach($item in $field.inputValueMap.entrySet())
						<input type="checkbox" name="${field.field}" value="$!{item.key}" title="$!{item.value}">
#end
					</div>
			    </div>
#elseif(${field.inputType}=="select")
#if($field.inputValueMap)
				<div class="layui-form-item">
					<label class="layui-form-label">${field.comment}#if(!$field.nullable)<font color="red">*</font>#end</label>
					<div class="layui-input-block">
						<select name="${field.field}" id="${field.field}" class="xf_membill_selectAge" #if(!$field.nullable)lay-verify="required"#end>
							<option value="">==请选择==</option>
#foreach($item in $field.inputValueMap.entrySet())
							<option value="$!{item.key}" #{ if ${model.modelL}?.${field.field}==$item.key} selected #{/if}>$!{item.value}</option>
#end
					   </select>
					</div>
				</div>
#elseif($field.inputType == "select"&&${field.inputValueTwo} != "")
				<div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}#if(!$field.nullable)<font color="red">*</font>#end</label>
			      <div class="layui-input-block">
			    	<select class="xfht_t_j_td_1_s" id="${field.field}" name="${field.field}" #if(!$field.nullable)lay-verify="required"#end>
			            <option value="" >==请选择==</option>
			            #{ list ${field.field}_list} 
						<option value="${ _?.id}" #{ if ${model.modelL}?.${field.field}==_?.id} selected #{/if}>${ _?.${field.inputValueTwo}}</option>
						#{/list}
			          </select>
			      </div>
			    </div>
#else
				<div class="layui-form-item ">
			      <label class="layui-form-label">${field.comment}#if(!$field.nullable)<font color="red">*</font>#end</label>
			      <div class="layui-input-block">
			    	<select class="xfht_t_j_td_1_s" id="${field.field}" name="${field.field}" #if(!$field.nullable)lay-verify="required"#end>
			            <option value="" >==请选择==</option>
			          </select>
			      </div>
			    </div>
#end
#else
			    <div class="layui-form-item">
			      <label class="layui-form-label">${field.comment}#if($field.validate=="mobile"||$field.validate=="email"||$field.validate=="url"||$field.validate=="identity"||!$field.nullable)<font color="red">*</font>#end</label>
			      <div class="layui-input-block"><input id="${field.field}" class="layui-input " type="text" placeholder="请输入${field.comment}" value="${${model.modelL}?.${field.field}}" #if($field.validate=="mobile")lay-verify="phone"#elseif($field.validate=="email")lay-verify="email"#elseif($field.validate=="url")lay-verify="url"#elseif($field.validate=="identity")lay-verify="identity"#elseif(!$field.nullable)lay-verify="required"#end></div>
			    </div>
#end
#end
#end
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="edit">立即修改</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
		</div>
	</div>
	 
</form>
<script type="text/javascript">
	$(function(){ 
#foreach($field in $fieldList)
#if(${field.inputType}=="checkbox")
    
        //初始化 复选框
	    var ${field.field}list = '${${model.modelL}?.${field.field}}'.split(',');
		$("input:checkbox[name='${field.field}']:checkbox").each(function(i) {
	      if (${field.field}list.inArray($(this).val())) {
	        $(this).attr("checked","checked");
	      }
	    });
#end
#end
    }); 

#foreach($field in $fieldList)
#if(${field.inputType}=="htmleditor")
    var ${field.field}Edit;
#end
#end
    KindEditor.ready(function(K) {
#foreach($field in $fieldList)
#if(${field.inputType}=="htmleditor")
      ${field.field}Edit = K.create('#${field.field}', {
         cssPath :"@{'public/javascripts/kindeditor-4.1.7/plugins/code/prettify.css'}",
         uploadJson : '@{FileUpload.uploadImage2()}',
      allowFileManager : true,
      allowUpload: true
      });
#end
#end
 });

layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
         function filterTime(val){
	        if(val < 10){
	            return "0" + val;
	        }else{
	            return val;
	        }
	    }
        var time = new Date();
#foreach($field in $fieldList)
#if(${field.inputType}=="date")
		var ${field.field}Time = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate());
        laydate.render({
	        elem: '#${field.field}',
	        type: 'date',
	        trigger : "click",
	        done : function(value, date, endDate){
	            ${field.field}Time = value;
	        }
	    });
#end
#if(${field.inputType}=="datetime")
var ${field.field}Time = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
        laydate.render({
	        elem: '#${field.field}',
	        type: 'datetime',
	        trigger : "click",
	        done : function(value, date, endDate){
	            ${field.field}Time = value;
	        }
	    });
#end
#end
 
    form.on("submit(edit)",function(data){
         
#foreach($field in $fieldList)
#if($field.isPk != "Y"&&${field.inputType}!="none")
#if(${field.inputType}=="file")
		var ${field.field} = $("#${field.field}src").attr("src");
		 $("#${field.field}").val($("#${field.field}src").attr("src"));
#elseif(${field.inputType}=="checkbox")
        var arr = new Array();
        $("input:checkbox[name='${field.field}']:checked").each(function(i){
             arr[i] = $(this).val();
        });
        var ${field.field} = arr.join(",");//将数组合并成字符串
#elseif(${field.inputType}=="datetime")
		var ${field.field} = $("#${field.field}").val();
#elseif(${field.inputType}=="htmleditor")
		var ${field.field} = ${field.field}Edit.html();
	  	${field.field} = replaceAllHTML(${field.field});
#elseif(${field.inputType}=="radio")
		var ${field.field} = $('input[name="${field.field}"]:checked').val();
#else
		var ${field.field} = $("#${field.field}").val().trim();
#end
#end
#end         
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.1});
       // 实际使用时的提交信息
        $.post("@{edit()}",{
        	"sign" : '${${model.modelL}?.sign}',
#foreach($field in $fieldList)
#if($field.isPk != "Y"&&${field.inputType}!="none")
			"${model.modelL}.${field.columnName}" : ${field.field},
#end
#end 
           
        },function(res){
        	top.layer.close(index);
        	if(res.toString().indexOf("<!DOCTYPE html>") != -1){
        		window.location.href="/"
        	}else if(res.code==0){
	            top.layer.msg(res.msg);
	            layer.closeAll("iframe");
	            //刷新父页面
	            parent.location.reload();
		        
	        }else{
		        top.layer.msg(res.msg);
	        }
        })
        return false;
    })
})
</script>